<?php
class XMLitem
{ 
	function XMLitem ($aa)
	{
		foreach ($aa as $k=>$v)
		{
			$this->$k = $aa[$k];
		}
	}
}

function readXMLfile($filename)
{
	$data = implode('', file($filename));
	$parser = xml_parser_create();
	$tdb = array();
	xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
	xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
	xml_parse_into_struct($parser, $data, $values, $tags);

	foreach ($tags as $key=>$val) 
	{
		if(($key == 'story') OR ($key == 'item') OR ($key == 'entry')) 
		{
			$molranges = $val;
			for ($i=0; $i < count($molranges); $i+=2) 
			{
				$offset = $molranges[$i] + 1;
				$len = $molranges[$i + 1] - $offset;
				$tdb[] = parseStory(array_slice($values, $offset, $len));
			}
		}
		else
		{
			continue;
		}
	}
	return $tdb;
}

function parseStory($mvalues)
{
	for ($i=0; $i < count($mvalues); $i++) 
	{
		if(isset($mvalues[$i]['value']))
		{
			$tagname = str_replace('digg:','',$mvalues[$i]['tag']);
			$tagname = str_replace('diggCount','digs',$tagname);
		
			$mol[$tagname] = $mvalues[$i]['value'];
		}
	}
	return new XMLitem($mol);
}

function log_adm_action($config,$summary,$details)
{
	mysql_query("INSERT INTO `".$config['db']['pre']."logs` ( `log_date` , `log_summary` , `log_details` ) VALUES ('".time()."', '".validate_input($summary)."', '".validate_input($details)."');");
}
?>